package JavaSE.CODE.ClassInCommonUse.Date_Calendar;

import java.util.Calendar;

public class CalDemo {
    public static void main(String[] args) {
        //1、创建 calendar 对象
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.getTime());
        System.out.println(calendar.getTimeInMillis());//自1970毫秒数
        //2、获取时间信息
        //获取年月日时分秒
        //以下的各个字段本质都是int，get方法根据值不同返回不同字段的值
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int date = calendar.get(Calendar.DATE);//DAY_OF_MONTH 等价
        int hour = calendar.get(Calendar.HOUR_OF_DAY);//HOUR 12小时制度
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        System.out.println("year " + year + " month " + month);
        //3、修改时间
        //修改指定字段为特定值
        calendar.set(Calendar.DATE,6);
        System.out.println(calendar.getTime());
        //4、add
        //在指定字段上加
        calendar.add(Calendar.DATE,1);
        System.out.println(calendar.getTime());
        calendar.add(Calendar.DATE, -1);
        System.out.println(calendar.getTime());
        //返回当前月份最大、最小天数
        System.out.println(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.getActualMinimum(Calendar.DAY_OF_MONTH));

    }
}
